import java.sql.*;

public class Sy2_2 {
    private static String driver="com.mysql.jdbc.Driver";
    private static String url="jdbc:mysql://localhost:3306/school?useSSL=false";
    private static String user="root";
    private static String password="123456";

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
            Class.forName(driver);
            Connection conn = DriverManager.getConnection(url,user,password);
            Statement stmt1= conn.createStatement();
            String sqlInsert="insert into ben values('179000','赵刚','男','gggg')";
            String sqlDelete="delete from ben where name='王五'";
            String sqlUpdate="update ben set sex='女' where sex='男'";
            String sqlSelect="select name,sex from ben";

            int a=stmt1.executeUpdate(sqlInsert);
            System.out.println("插入操作影响"+a+"条记录");

            Statement stmt2= conn.createStatement();
            int b=stmt2.executeUpdate(sqlDelete);
            System.out.println("删除操作影响"+b+"条记录");

            Statement stmt3= conn.createStatement();
            int c= stmt3.executeUpdate(sqlUpdate);
            System.out.println("更新操作影响"+c+"条记录");

            Statement stmt4= conn.createStatement();
            ResultSet rs=stmt4.executeQuery(sqlSelect);
            while (rs.next()){
                String name=rs.getString(1);
                String sex=rs.getString(2);
                System.out.println("姓名："+name+" 性别："+sex);
            }

    }
}

